﻿@model ProductReviewOverviewModel
@using System.Globalization
@{
    int ratingPercent = 0;
    if (Model.TotalReviews != 0)
    {
        ratingPercent = ((Model.RatingSum * 100) / Model.TotalReviews) / 5;
    }
}
<div class="product-reviews-overview d-inline-flex align-items-center flex-wrap" @if (Model.TotalReviews > 0) { <text> itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating" </text> }>
    <div class="product-review-box d-inline-block order-1">
        <div class="ratings">
            <div class="rating-box">
                <div class="rating" style="width: @(ratingPercent)%">
                </div>
            </div>
        </div>
    </div>
    @if (Model.TotalReviews > 0)
    {
        <div class="product-review-links order-3">
            <a class="btn btn-sm py-0 pr-0 review-scroll-button" href="#review-tab">
                @Model.TotalReviews
                @T("Reviews.Overview.Reviews")
            </a>
        </div>
        @* microdata info*@
        decimal ratingValue = ratingPercent / (decimal)20;
        <div class="order-2 mr-2 review-count" itemprop="ratingValue">
            <a class="btn btn-sm py-0 pr-0 review-scroll-button">
                <strong>(@ratingValue.ToString("0.0", new CultureInfo("en-US")))</strong>
            </a>
        </div>
        <span itemprop="reviewCount" style="display: none;">@Model.TotalReviews</span>
    }
    else
    {
        <div class="product-no-reviews order-3">
            <a class="btn btn-sm py-0 pr-0" href="@Url.RouteUrl("ProductReviews", new { productId = Model.ProductId })">@T("Reviews.Overview.First")</a>
        </div>
    }
</div>
